﻿
using Ops.Mpc.Wcf;
using System;
using Ops.Mpc.Events;
using Ops.Mpc.Collections;
using Ops.Mpc.Filters;

namespace Ops.Mpc.ExampleApplication.ExampleService
{
    public class ExampleServiceContext : ServiceContext<ExampleServiceClient, ExampleService>, IExampleServiceContext
    {
 

        #region Constructors
        public ExampleServiceContext()
        {
            this.ServiceClient = new ExampleServiceClient(this.GetBinaryBinding(),this.GetEndpointAddress());
        }

        #endregion

        #region Methods

        protected override string GetServiceUri()
        {
            return this.GetServerUri() + "/Services/ExampleService.svc";
        }

        public void CreatePerson(string firstName, string lastName, AsyncCompleteHandler<Person> asyncCompleteHandler, ErrorHandler errorEventHandler, object context = null)
        {
            this.Service.BeginCreatePerson(firstName, lastName, this.GetAsyncCallback(this.Service.EndCreatePerson, asyncCompleteHandler, errorEventHandler, true), context);
        }

        public void GetPersons(Pager pager, AsyncCompleteHandler<Person[]> asyncCompleteHandler, ErrorHandler errorEventHandler, object context = null)
        {
            this.Service.BeginGetPersons(pager, this.GetAsyncCallback(this.Service.EndGetPersons,asyncCompleteHandler, errorEventHandler,true),context);
        }

        public void GetPersons(Filter[] filters, AsyncCompleteHandler<Pager> asyncCompleteHandler, ErrorHandler errorEventHandler, object context = null)
        {
            this.Service.BeginGetPersonsPager(filters, this.GetAsyncCallback(this.Service.EndGetPersonsPager, asyncCompleteHandler, errorEventHandler, true), context);
        }
        #endregion 
    }
}
